/**
	Object MenuSlider
	Args :	
			_container: 
			_nav:		
			_floatNav:	
	Ddescription :		
*/
function MenuSlider ( _container, _nav, _floatNav ){
	this.container = _container;
	this.nav = _nav;
	this.floatNav = _floatNav.show();
	this.articles = this.container.find('article');
	// Height value 
	this.articleHeight = parseInt( this.articles.eq(0).css('height') );
	
	this.articleLength = this.articles.length;
	this.current = 0;
}


/**
	Function: 			MenuSlider.transition
	Args:
		_duration:		Animation's duration
		_coords: 		Where to move [optional : if not present, calculate the position using
						current value]
	Description:		Make the transition (using animate) to the _coords or calculate coords itself
*/
MenuSlider.prototype.transition = function( _coords ){
	this.container.animate({
		'margin-top' : _coords || -( this.current * this.articleHeight )
	});
}


/**
	Function:		MenuSlider.setCoordinates
	Args:
		_dir:		Direction to setup coordinates (up or down in our case)
	Description: 	Set the current attributes in order the MenuSlider always know
					where in the list of article he is
*/
MenuSlider.prototype.setCoordinates = function( _dir, _current ){
	var pos = this.current;
	var aLength = this.articleLength;
	
	if( _dir ){
		pos += ( ~~( _dir === 'down') || -1 );
		this.current = ( pos < 0 ) ? aLength - 1 : pos % aLength;
	}else if( _current ){
		this.current = _current;
	}
	
	return (_current || pos);
}

/**
	Function: 		MenuSlider.fireOwnEvent	
	Args:			
		_event: 	The event to fire
	Description:	Fire the event associated to the newly shown panel in order 
					the panel know that is going to be shown and execute it's init method
*/
MenuSlider.prototype.fireOwnEvent = function( _event ){
	var event = _event || '';
	var li = $('.mainmenu li');
	var container = this.container;
	var current = this.current;
	
	if( _event ){
	
		container.trigger( _event );
		
	}else{
		// Grab the event from the li with the data-order === this.current value
		$.each(li, function(index, obj){
			var $obj = $(obj);
			
			if( $obj.data( 'order' ) === current ){
				container.trigger( $obj.data( 'ownevent' ) );
			}
		});
	}
}